#ifndef _THREADPOOL_H_
#define _THREADPOOL_H_

#include <pthread.h>

typedef struct arg1{
    int connfd;
    int bufsize;
} arg1; // args for first type of job (list_seats)

typedef struct arg2{
    int connfd;
    int bufsize;
    int seat_num;
    int customer_num;
} arg2; // args for second type of job (view, confirm, cancel)

// it is one task
typedef struct pool_task_t{
    void (*function)(void *);
    void *argument;
    struct pool_task_t* next;
} pool_task_t;

// it is the thread pool
typedef struct pool_t {
  pthread_mutex_t lock;
  pthread_cond_t get_task;
  pthread_cond_t fill_task;
  pthread_t *threads;
  pool_task_t *first_queue; // head of linked list of task
  pool_task_t *business_queue;
  pool_task_t *coach_queue;
  int first_queue_size;
  int business_queue_size;
  int coach_queue_size;
  int task_queue_size_limit;
  int thread_count;
} pool_t;

#define MAX_THREADS   20
#define TASK_QUEUE_SIZE  20

pool_t *pool_create(int queue_size, int num_threads);
int pool_add_task(pool_t *pool, void (*function)(void *), void *argument, int priority);
int pool_destroy(pool_t *pool);

void List_seats(void* arg);
void View_seat(void* arg);
void Confirm_seat(void* arg);
void Cancel(void* arg);

#endif
